#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Currency Converter Copyright (C) 2009  Chris Marsh
#
# Currency Converter is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or any later version.
#
# This program is distributed in the hope that it will be useful, 
# but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# *********************************************************************************
#
# about_dlg.py, This module represents the gui of the About dialog window.
#
# *********************************************************************************

import platform
import qcurrency_rc
from PyQt4.QtCore import *
from PyQt4.QtGui import *
    
# *********************************************************************************

class AboutDialog(QDialog):
    
    def __init__(self,  version = "Debug",  parent=None):
        super(AboutDialog,  self).__init__(parent)
        
        size = QSize(550,  250)
        self.setMinimumSize(size)
        
        aboutText = QTextEdit("""
            <b>QCurrency Converter</b> v %s
            <p>Qcurrency is a currency converter for international exchange rates.
            Exchange rate data is updated from the internet and stored locally for off-line use.
            <p>It is written using the PyQt Python bindings for the Qt GUI toolkit.
            <p>For more information see: http://qcurrency.garage.maemo.org/
            <p>Python %s - Qt %s- PyQt %s on %s %s
            """ % (version,
                   platform.python_version(),
                   QT_VERSION_STR,
                   PYQT_VERSION_STR,
                   platform.system(),
                   platform.release()
                   ))
        aboutText.setReadOnly(True)
        
        authorsText = QTextEdit("""
            Copyright &copy; 2009 Chris Marsh.
        """)
        authorsText.setReadOnly(True)
        
        thanksText = QTextEdit("""
            <p>Time Genie for providing the exchange rate data.
            <br>http://www.timegenie.com/
            <p>4International Flags for providing the basis of the flag icons.
            <br>http://www.33ff.com/flags/
        """)
        thanksText.setReadOnly(True)
        
        licenseText = QTextEdit()
        inputFile = QFile(":/license.txt")
        inputFile.open(QIODevice.ReadOnly)
        fileInput = QTextStream(inputFile)
        line = QString(fileInput.readAll())
        inputFile.close()
        licenseText.append(line)
        licenseText.moveCursor(QTextCursor.Start)
        licenseText.setReadOnly(True)
    
        tabWidget = QTabWidget()
        
        aboutTab = QWidget()
        aboutLayout = QVBoxLayout()
        aboutLayout.addWidget(aboutText)
        aboutTab.setLayout(aboutLayout)
        authorsTab = QWidget()
        authorsLayout = QVBoxLayout()
        authorsLayout.addWidget(authorsText)
        authorsTab.setLayout(authorsLayout)
        thanksTab = QWidget()
        thanksLayout = QVBoxLayout()
        thanksLayout.addWidget(thanksText)
        thanksTab.setLayout(thanksLayout)
        licenseTab = QWidget()
        licenseLayout = QVBoxLayout()
        licenseLayout.addWidget(licenseText)
        licenseTab.setLayout(licenseLayout)
        
        tabWidget.addTab(aboutTab,  "&About")
        tabWidget.addTab(authorsTab,  "A&uthors")
        tabWidget.addTab(thanksTab,  "&Thanks To")
        tabWidget.addTab(licenseTab,  "&License")
        
        buttonBox = QDialogButtonBox(QDialogButtonBox.Ok)
        buttonBox.button(QDialogButtonBox.Ok).setDefault(True)
        
        layout = QVBoxLayout()
        layout.addWidget(tabWidget)
        layout.addWidget(buttonBox)
        
        self.connect(buttonBox,  SIGNAL("accepted()"),  self,  SLOT("accept()"))
        
        self.setLayout(layout)
        self.setWindowTitle("About")

# *********************************************************************************

def main():
    import sys
    app = QApplication(sys.argv)
    aboutDlg = AboutDialog()
    aboutDlg.show()
    sys.exit(app.exec_())

if __name__ == "__main__":
    main()
